import { ReqCategorizeList, ReqScildList, ReqFloorList } from '@/api/index';

//存储数据
const state = {
  category: [],
  scild: [],
  floor: [],
};

// 同步更新state数据,mutations 中的方法名必须大写
const mutations = {
  SAVE_CATEGORY_LIST(state, value) {
    state.category = value;
  },
  SAVE_SCILD_LIST(state, value) {
    state.scild = value;
  },
  SAVE_FLOOR_LIST(state, value) {
    state.floor = value;
  },
};

//异步方法，调用mutations 方法来同步更新state数据
const actions = {
  async asyncGetCategoryList({ commit }) {
    let data = await ReqCategorizeList();

    commit('SAVE_CATEGORY_LIST', data);
  },
  async asyncGetScildList({ commit }) {
    let data = await ReqScildList();
    commit('SAVE_SCILD_LIST', data);
  },
  async asyncGetFloorList({ commit }) {
    let data = await ReqFloorList();
    commit('SAVE_FLOOR_LIST', data);
  },
};

//类似于computed
const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
